{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [],
   "source": [
    "input = \"\"\"101010000100\n",
    "100001010100\n",
    "111100000101\n",
    "010000000010\n",
    "001101100010\n",
    "100110110101\n",
    "110100101101\n",
    "101010000001\n",
    "110011110000\n",
    "110000011011\n",
    "010111010100\n",
    "000101101001\n",
    "110001101100\n",
    "110100111101\n",
    "000101101100\n",
    "011111101000\n",
    "001011101100\n",
    "001011000110\n",
    "000011110110\n",
    "101110010111\n",
    "010011101001\n",
    "011111100101\n",
    "000001110101\n",
    "100001010010\n",
    "001110010101\n",
    "111010000110\n",
    "100111001111\n",
    "110010000101\n",
    "001111100001\n",
    "000110010101\n",
    "111001111011\n",
    "110000111111\n",
    "011101110001\n",
    "111001000011\n",
    "100110101011\n",
    "101101100010\n",
    "110100100101\n",
    "101011111000\n",
    "001101110011\n",
    "011000010011\n",
    "101010011111\n",
    "101011000110\n",
    "011111101001\n",
    "000011100000\n",
    "101111000101\n",
    "010000010111\n",
    "010110111000\n",
    "101110111100\n",
    "000001010011\n",
    "011011000001\n",
    "110101101011\n",
    "011110101100\n",
    "010001011100\n",
    "110111000011\n",
    "010101101001\n",
    "110011011111\n",
    "111101111101\n",
    "110011010111\n",
    "100100100110\n",
    "011100101111\n",
    "100111010000\n",
    "110000110111\n",
    "111000010111\n",
    "100001010001\n",
    "101010001111\n",
    "010101100111\n",
    "001010101111\n",
    "000001011011\n",
    "111100011110\n",
    "101110100010\n",
    "011111011110\n",
    "111110111011\n",
    "001110110111\n",
    "010011010000\n",
    "111011011101\n",
    "101110110100\n",
    "111010011111\n",
    "011011011101\n",
    "110001110100\n",
    "000010011010\n",
    "011101010101\n",
    "100000001000\n",
    "000100100001\n",
    "011110000000\n",
    "111100101010\n",
    "001100100010\n",
    "101001101110\n",
    "111010001110\n",
    "101011111101\n",
    "010011100101\n",
    "110111110101\n",
    "111000111010\n",
    "010000000111\n",
    "001101111111\n",
    "101101001100\n",
    "111001000100\n",
    "001100000000\n",
    "011011100100\n",
    "010011110000\n",
    "000001111110\n",
    "110011001010\n",
    "001001000110\n",
    "011011001101\n",
    "001111111111\n",
    "001010101010\n",
    "011110110100\n",
    "110101111111\n",
    "001111011101\n",
    "001101001111\n",
    "000000111100\n",
    "001101101010\n",
    "011000001001\n",
    "100100101101\n",
    "000000111011\n",
    "011101110011\n",
    "101011110010\n",
    "010110000010\n",
    "000101000000\n",
    "010100111011\n",
    "000111010011\n",
    "111011111000\n",
    "011110010000\n",
    "000011101001\n",
    "101001110000\n",
    "011101111101\n",
    "100010010100\n",
    "011100001011\n",
    "110011011000\n",
    "100010001110\n",
    "100101010111\n",
    "100101101110\n",
    "010010000011\n",
    "101011000111\n",
    "100100100111\n",
    "001000001000\n",
    "110010100011\n",
    "111100001011\n",
    "011010001000\n",
    "000011010000\n",
    "000111111011\n",
    "110100101110\n",
    "011110000011\n",
    "100101000011\n",
    "001100100001\n",
    "000010100011\n",
    "111101111011\n",
    "001010101101\n",
    "101110110010\n",
    "101011011010\n",
    "111010101011\n",
    "001110010001\n",
    "111110101011\n",
    "111111001011\n",
    "011100011101\n",
    "111100111001\n",
    "101011000000\n",
    "100000010111\n",
    "000101111101\n",
    "001011001110\n",
    "111101101010\n",
    "110001000000\n",
    "101111110100\n",
    "010111010110\n",
    "111011100001\n",
    "111100010100\n",
    "000100011100\n",
    "000011011011\n",
    "010000001001\n",
    "100100011001\n",
    "001010011110\n",
    "110001110011\n",
    "100010000110\n",
    "001110001101\n",
    "111001111111\n",
    "100100000011\n",
    "001001101011\n",
    "100101010011\n",
    "010111100010\n",
    "001110101100\n",
    "000110111111\n",
    "010011101101\n",
    "011101011011\n",
    "101000111100\n",
    "101100001011\n",
    "000011100011\n",
    "111110110011\n",
    "100011001101\n",
    "000100100011\n",
    "110011111010\n",
    "011001100111\n",
    "000011100110\n",
    "011001001110\n",
    "000111011110\n",
    "010101111101\n",
    "101100101011\n",
    "111110101111\n",
    "101101011010\n",
    "000101110111\n",
    "101011010010\n",
    "101100101010\n",
    "111101100100\n",
    "011100101000\n",
    "100111100010\n",
    "000110110011\n",
    "000000100001\n",
    "011110001110\n",
    "000111110010\n",
    "001100011001\n",
    "000001111001\n",
    "001111011111\n",
    "110011001111\n",
    "101010110101\n",
    "011010110100\n",
    "100010110011\n",
    "111111111101\n",
    "010001110011\n",
    "001101110000\n",
    "001110100011\n",
    "110010101011\n",
    "001010001000\n",
    "101010010000\n",
    "000101011111\n",
    "111000111101\n",
    "011101010110\n",
    "100111010011\n",
    "010010010000\n",
    "111000101101\n",
    "110000110010\n",
    "010110010001\n",
    "011101001110\n",
    "001010011111\n",
    "110011010001\n",
    "100000100001\n",
    "110110001100\n",
    "111110101101\n",
    "101110011011\n",
    "100101011011\n",
    "001010011010\n",
    "111101000110\n",
    "100010011000\n",
    "001101101001\n",
    "010001010100\n",
    "011100110010\n",
    "011010100110\n",
    "101111011110\n",
    "100011010111\n",
    "000011111110\n",
    "000110101011\n",
    "000011111000\n",
    "101110101100\n",
    "101100011110\n",
    "011010101011\n",
    "010001110111\n",
    "101010100001\n",
    "011011011001\n",
    "110011101011\n",
    "110001011111\n",
    "000010101100\n",
    "100000011101\n",
    "010000101000\n",
    "001111101100\n",
    "111100011100\n",
    "101110101101\n",
    "110111110100\n",
    "010101000001\n",
    "011110000001\n",
    "111100010101\n",
    "011110010001\n",
    "001101001100\n",
    "001011011100\n",
    "010110101111\n",
    "000100101011\n",
    "001100001010\n",
    "000101101111\n",
    "010111110110\n",
    "100010111011\n",
    "000110001011\n",
    "010111010011\n",
    "101001000101\n",
    "011000111101\n",
    "001001101001\n",
    "010100010000\n",
    "111111001000\n",
    "011110100011\n",
    "011000101100\n",
    "111101110100\n",
    "101010010110\n",
    "111101010111\n",
    "011001100100\n",
    "001110001110\n",
    "111110110000\n",
    "110100011111\n",
    "000101101110\n",
    "011000110011\n",
    "111001111110\n",
    "011110101110\n",
    "010011001101\n",
    "000011011111\n",
    "111001010111\n",
    "000000111101\n",
    "100101100100\n",
    "100001110101\n",
    "111100100101\n",
    "001110000110\n",
    "011100001101\n",
    "100100110011\n",
    "001100000100\n",
    "010011001110\n",
    "111111110011\n",
    "101110111111\n",
    "100111011000\n",
    "111110101110\n",
    "100010101100\n",
    "010101010000\n",
    "011101100001\n",
    "010010011101\n",
    "001111010111\n",
    "011100010101\n",
    "111101110101\n",
    "010100001110\n",
    "011000111000\n",
    "100110100101\n",
    "110101001111\n",
    "000011011010\n",
    "110101011010\n",
    "110010111100\n",
    "110111000101\n",
    "100111000100\n",
    "110101011111\n",
    "110110011101\n",
    "010111101010\n",
    "111001010011\n",
    "001001100100\n",
    "001101101101\n",
    "011100001100\n",
    "000110010011\n",
    "010101010110\n",
    "000011001101\n",
    "101001001100\n",
    "111011100011\n",
    "011011110100\n",
    "001110100001\n",
    "001000101001\n",
    "001100010111\n",
    "110000001101\n",
    "100010111101\n",
    "000110111101\n",
    "111001101101\n",
    "101110100000\n",
    "101001100101\n",
    "101100011001\n",
    "111010101101\n",
    "010101011100\n",
    "111100011000\n",
    "101111110101\n",
    "110111110011\n",
    "000000101100\n",
    "010110101011\n",
    "100111011011\n",
    "010111011000\n",
    "000101110100\n",
    "001010110101\n",
    "000010111011\n",
    "001110000001\n",
    "010000010000\n",
    "101110010101\n",
    "000000111110\n",
    "110100011000\n",
    "110110111100\n",
    "100010110100\n",
    "001000101110\n",
    "011001010101\n",
    "000100010001\n",
    "100011100010\n",
    "100011100000\n",
    "100010101001\n",
    "100101111000\n",
    "110000011110\n",
    "011000011101\n",
    "101101101101\n",
    "100110010110\n",
    "111110001000\n",
    "111001011010\n",
    "001110110001\n",
    "100000010101\n",
    "111101001111\n",
    "000010010100\n",
    "101100110001\n",
    "100101011000\n",
    "010101001010\n",
    "000111100000\n",
    "100010101000\n",
    "011101110100\n",
    "110110001110\n",
    "010001000110\n",
    "100101001100\n",
    "110000010111\n",
    "011000101111\n",
    "001111001000\n",
    "001110010010\n",
    "000010101101\n",
    "011000010000\n",
    "011011101010\n",
    "001010000101\n",
    "001010110010\n",
    "100001100000\n",
    "110111010000\n",
    "100010001101\n",
    "010011001011\n",
    "110011001110\n",
    "110111000110\n",
    "000001110010\n",
    "110010001001\n",
    "111100100100\n",
    "000101110110\n",
    "000100011001\n",
    "111111010101\n",
    "011010100000\n",
    "110111000100\n",
    "011101011010\n",
    "100011111110\n",
    "100001001101\n",
    "100111000001\n",
    "100001011111\n",
    "010010000010\n",
    "010111101011\n",
    "000001111100\n",
    "001100110111\n",
    "100111011100\n",
    "101000101100\n",
    "100111111111\n",
    "101101000110\n",
    "101111001111\n",
    "011010110101\n",
    "111000110000\n",
    "100010101101\n",
    "011110100100\n",
    "001101110101\n",
    "011101011000\n",
    "010101011000\n",
    "010110110011\n",
    "110101011110\n",
    "111010101100\n",
    "110111000000\n",
    "101011110110\n",
    "100111101010\n",
    "110001111110\n",
    "001000111001\n",
    "110001111011\n",
    "011010000100\n",
    "000101001010\n",
    "010111000001\n",
    "100000101000\n",
    "011010111001\n",
    "010011101110\n",
    "011011010101\n",
    "010110101100\n",
    "000010100110\n",
    "011111101011\n",
    "101111100110\n",
    "110010001100\n",
    "100000110100\n",
    "100111100011\n",
    "110111101010\n",
    "110010010000\n",
    "000011010010\n",
    "111000000111\n",
    "100101100101\n",
    "100011101110\n",
    "111110110110\n",
    "111001011000\n",
    "010100111101\n",
    "111110001100\n",
    "000110011101\n",
    "000010110010\n",
    "101000111011\n",
    "101000010100\n",
    "001001110001\n",
    "111010101111\n",
    "100011000101\n",
    "111011001100\n",
    "000000011100\n",
    "101010111001\n",
    "110111101000\n",
    "011000110001\n",
    "100100110010\n",
    "011101011101\n",
    "001011111111\n",
    "101011100110\n",
    "101011010111\n",
    "100001011010\n",
    "100100010100\n",
    "000010000010\n",
    "101101010111\n",
    "001011001101\n",
    "101100111010\n",
    "110101000001\n",
    "101101110100\n",
    "100100110111\n",
    "110001101001\n",
    "010101010001\n",
    "110110001111\n",
    "000011011101\n",
    "111111110001\n",
    "011110110101\n",
    "111100110101\n",
    "011111011011\n",
    "101001111110\n",
    "110101101010\n",
    "111001000001\n",
    "010100110001\n",
    "111011100101\n",
    "101011101101\n",
    "010010010001\n",
    "111110001001\n",
    "100100111000\n",
    "111110111100\n",
    "001000000000\n",
    "111110111101\n",
    "110010101101\n",
    "100110111110\n",
    "001010100010\n",
    "101011001001\n",
    "111101010100\n",
    "110011100000\n",
    "100111000111\n",
    "000011000110\n",
    "101010100000\n",
    "101011011000\n",
    "000010110110\n",
    "111100000011\n",
    "000000010010\n",
    "101010110111\n",
    "001111111000\n",
    "100011110101\n",
    "001001000010\n",
    "111011101110\n",
    "001111011100\n",
    "111011101010\n",
    "011011000101\n",
    "000001000010\n",
    "001000100100\n",
    "001110110011\n",
    "010101011011\n",
    "100011011010\n",
    "111000001110\n",
    "110010000000\n",
    "100101100010\n",
    "100111110011\n",
    "010011100001\n",
    "010001111010\n",
    "110101010101\n",
    "101111000001\n",
    "001001011100\n",
    "011110000110\n",
    "111001011110\n",
    "111001111010\n",
    "110100010011\n",
    "001000010010\n",
    "111110000010\n",
    "001000011001\n",
    "010100011101\n",
    "101111101011\n",
    "010111001111\n",
    "111011011010\n",
    "111101111010\n",
    "001111001111\n",
    "111110100000\n",
    "100000011000\n",
    "110100111100\n",
    "001011101000\n",
    "010011011001\n",
    "010000010011\n",
    "100010011010\n",
    "110001111111\n",
    "011010111011\n",
    "101001111100\n",
    "111110111000\n",
    "110000001100\n",
    "010000100101\n",
    "110101100111\n",
    "110011100010\n",
    "110001001101\n",
    "011101111011\n",
    "011010101101\n",
    "011000011111\n",
    "101011101001\n",
    "010100000010\n",
    "110100100010\n",
    "101010101101\n",
    "010000111101\n",
    "110100110110\n",
    "101100001100\n",
    "001011100011\n",
    "011110011001\n",
    "000000001010\n",
    "000010111001\n",
    "001000001010\n",
    "100101001010\n",
    "010000000011\n",
    "101011101100\n",
    "011101010111\n",
    "100100101001\n",
    "110100100100\n",
    "110101001101\n",
    "010100010111\n",
    "011001001100\n",
    "101100111001\n",
    "100001001011\n",
    "101100011111\n",
    "001111101101\n",
    "010011110101\n",
    "011100010011\n",
    "000010011101\n",
    "011110001101\n",
    "010001010011\n",
    "001001111001\n",
    "100111110100\n",
    "111011000111\n",
    "101010110000\n",
    "010010111011\n",
    "100010110111\n",
    "110011111110\n",
    "101111000111\n",
    "111011000000\n",
    "110001110001\n",
    "001100100011\n",
    "001011100111\n",
    "101001110010\n",
    "111001001101\n",
    "000010000011\n",
    "001011010010\n",
    "110111101110\n",
    "001000010110\n",
    "000111000111\n",
    "010001101010\n",
    "011001110101\n",
    "011000110000\n",
    "000111100100\n",
    "101010111101\n",
    "010010010010\n",
    "101111001001\n",
    "001100100111\n",
    "100111111000\n",
    "100000010011\n",
    "101101111001\n",
    "000110011110\n",
    "100001111101\n",
    "110000100001\n",
    "101110110110\n",
    "111010000010\n",
    "101010001010\n",
    "000001010000\n",
    "101011110100\n",
    "001101010110\n",
    "100011010011\n",
    "101011101110\n",
    "011101101101\n",
    "100101010110\n",
    "101011100111\n",
    "100010010000\n",
    "000101011101\n",
    "011000001000\n",
    "111011111110\n",
    "101001101111\n",
    "101000111001\n",
    "100010100111\n",
    "011111000101\n",
    "100010001111\n",
    "110011011101\n",
    "111101100111\n",
    "111101100000\n",
    "010111000100\n",
    "111010010010\n",
    "001011100100\n",
    "001000110100\n",
    "100110010111\n",
    "111010011100\n",
    "100101001101\n",
    "101001110110\n",
    "011001110010\n",
    "000111010110\n",
    "010000011101\n",
    "101100100001\n",
    "101001001000\n",
    "000111100011\n",
    "100110110000\n",
    "110011001001\n",
    "001011001001\n",
    "110101011100\n",
    "010001100101\n",
    "000000101010\n",
    "001001100001\n",
    "101001100011\n",
    "110001110101\n",
    "111001010010\n",
    "111011011000\n",
    "101101011000\n",
    "101001000010\n",
    "010110101110\n",
    "001000101101\n",
    "111001100111\n",
    "011110110000\n",
    "100100101100\n",
    "010100011111\n",
    "111000000000\n",
    "001000010111\n",
    "000000111010\n",
    "111011111001\n",
    "000110100011\n",
    "011110100110\n",
    "011011101100\n",
    "000000001101\n",
    "100101111011\n",
    "101110111001\n",
    "100111001110\n",
    "101110000101\n",
    "001110001111\n",
    "001000110010\n",
    "111101000011\n",
    "000100011011\n",
    "010111010101\n",
    "001100100000\n",
    "100101101011\n",
    "010111000011\n",
    "010101111010\n",
    "011000000111\n",
    "011011000110\n",
    "101001011100\n",
    "101101100000\n",
    "101110101001\n",
    "111000111110\n",
    "110010000010\n",
    "110111111001\n",
    "100100111011\n",
    "111011010011\n",
    "100001101000\n",
    "111110001110\n",
    "110100011010\n",
    "010101000111\n",
    "000110100111\n",
    "001111000101\n",
    "000111000011\n",
    "110001001001\n",
    "011000100010\n",
    "101001111011\n",
    "110001000101\n",
    "110111010011\n",
    "011100011011\n",
    "011011001011\n",
    "100101011111\n",
    "000000101000\n",
    "100001100110\n",
    "000100110101\n",
    "110100100000\n",
    "000101000001\n",
    "101111001100\n",
    "111101011100\n",
    "010001110110\n",
    "000001001100\n",
    "100100001110\n",
    "000100100111\n",
    "001101000001\n",
    "100011100110\n",
    "110110110010\n",
    "110001011001\n",
    "110001001000\n",
    "001011100010\n",
    "111011001011\n",
    "100101111110\n",
    "001001111011\n",
    "110101111010\n",
    "101100111100\n",
    "101111101000\n",
    "111110100101\n",
    "011110111101\n",
    "010110111101\n",
    "111010100010\n",
    "111100001100\n",
    "000001000111\n",
    "111011000100\n",
    "101000111000\n",
    "011101100100\n",
    "011000100000\n",
    "110001111101\n",
    "111010100011\n",
    "110010001010\n",
    "000101001111\n",
    "010110001001\n",
    "101101101010\n",
    "101100110010\n",
    "010010000111\n",
    "111110100010\n",
    "011011000011\n",
    "111111011011\n",
    "001011001000\n",
    "010001011101\n",
    "101101110010\n",
    "010001001101\n",
    "101000110101\n",
    "100100010011\n",
    "101010010001\n",
    "101010110011\n",
    "101110011110\n",
    "001010000110\n",
    "000011000000\n",
    "101111011000\n",
    "100001010110\n",
    "010111101101\n",
    "001110011011\n",
    "100100011110\n",
    "100001011001\n",
    "010100111111\n",
    "011101000110\n",
    "111010111011\n",
    "000010100100\n",
    "010011100111\n",
    "110001000011\n",
    "000100111010\n",
    "100111001000\n",
    "010110011000\n",
    "101101110101\n",
    "110101001011\n",
    "000101101010\n",
    "011110101111\n",
    "110111100111\n",
    "111100111011\n",
    "001000101011\n",
    "000010000101\n",
    "110101101101\n",
    "010000100111\n",
    "100110001011\n",
    "011001000110\n",
    "111101001000\n",
    "000010011000\n",
    "110101100001\n",
    "100100101111\n",
    "110111001010\n",
    "111011111011\n",
    "010111001000\n",
    "011011110011\n",
    "111011110010\n",
    "100011000111\n",
    "011001100011\n",
    "001111000000\n",
    "101001101010\n",
    "111111011101\n",
    "000100110001\n",
    "111010010000\n",
    "011111100000\n",
    "101110100101\n",
    "100011011110\n",
    "001000010001\n",
    "110110100000\n",
    "100011111011\n",
    "100011000001\n",
    "000011010100\n",
    "110101110110\n",
    "001100010010\n",
    "111011011001\n",
    "010101101111\n",
    "110111100100\n",
    "101000110100\n",
    "110001010100\n",
    "100010010111\n",
    "000111110111\n",
    "101101101100\n",
    "110100110001\n",
    "011011100000\n",
    "010011000000\n",
    "110101101000\n",
    "100011110001\n",
    "001011111101\n",
    "011000110110\n",
    "011101101010\n",
    "000011111100\n",
    "010110110111\n",
    "111101111001\n",
    "110111011101\n",
    "010001011000\n",
    "100110000101\n",
    "011101100101\n",
    "111101011000\n",
    "011110001000\n",
    "001011001100\n",
    "110110011111\n",
    "010111011100\n",
    "001111001110\n",
    "110010110110\n",
    "111011110110\n",
    "100000101100\n",
    "111100101011\n",
    "000100011110\n",
    "010111110000\n",
    "110011010101\n",
    "110000111110\n",
    "011100100011\n",
    "000101011000\n",
    "101110011100\n",
    "010111111000\n",
    "110010111101\n",
    "000001011010\n",
    "100010101011\n",
    "110001011100\n",
    "100100001100\n",
    "010101101010\n",
    "001101011110\n",
    "011011101111\n",
    "011100110011\n",
    "100011110000\n",
    "011110011111\n",
    "001011011101\n",
    "011010110010\n",
    "101000110111\n",
    "001001100111\n",
    "010111101111\n",
    "110110010001\n",
    "110001100000\n",
    "011001100101\n",
    "000110110111\n",
    "010010001100\n",
    "101100001010\n",
    "101010011110\n",
    "001010010110\n",
    "101001001001\n",
    "100110000010\n",
    "011101101111\n",
    "011010011001\n",
    "010111000010\n",
    "101001111111\n",
    "000010001001\n",
    "101000100011\n",
    "001110100100\n",
    "011011010000\n",
    "100111110101\n",
    "100110100000\n",
    "000101011001\n",
    "001100010110\n",
    "110011110010\n",
    "011000100001\n",
    "001100010101\n",
    "110010001101\n",
    "100011101001\n",
    "001100011110\n",
    "110101111101\n",
    "111111101000\n",
    "000011110001\n",
    "010000010100\n",
    "001101011001\n",
    "100111000000\n",
    "011100000101\n",
    "110110000000\n",
    "110011011001\n",
    "001100010011\n",
    "110011110110\n",
    "010010011111\n",
    "100001101001\n",
    "011100111100\n",
    "001011110001\n",
    "001010010011\n",
    "010000000101\n",
    "000100010011\n",
    "111101011001\n",
    "111100110110\n",
    "111000011100\n",
    "111101101110\n",
    "000101111011\n",
    "010101110101\n",
    "011110111111\n",
    "100000000011\n",
    "111000000011\n",
    "000010100000\n",
    "001110100010\n",
    "011001000010\n",
    "100001011110\n",
    "010100100111\n",
    "000111110011\n",
    "110100110101\n",
    "011001111100\n",
    "111101110110\n",
    "001101010101\n",
    "110110000010\n",
    "010101001101\n",
    "110100110000\n",
    "000100010101\n",
    "111011101001\n",
    "110111111111\n",
    "000000110010\n",
    "100111110110\n",
    "001000011111\n",
    "100100000101\n",
    "011001110110\n",
    "010010100110\n",
    "000101010111\n",
    "101001100000\n",
    "110011101110\n",
    "010001100001\n",
    "011100000100\n",
    "010100100000\n",
    "100000100100\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "      <th>5</th>\n",
       "      <th>6</th>\n",
       "      <th>7</th>\n",
       "      <th>8</th>\n",
       "      <th>9</th>\n",
       "      <th>10</th>\n",
       "      <th>11</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>995</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>996</th>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>997</th>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>999</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1000 rows × 12 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     0   1   2   3   4   5   6   7   8   9   10  11\n",
       "0     1   0   1   0   1   0   0   0   0   1   0   0\n",
       "1     1   0   0   0   0   1   0   1   0   1   0   0\n",
       "2     1   1   1   1   0   0   0   0   0   1   0   1\n",
       "3     0   1   0   0   0   0   0   0   0   0   1   0\n",
       "4     0   0   1   1   0   1   1   0   0   0   1   0\n",
       "..   ..  ..  ..  ..  ..  ..  ..  ..  ..  ..  ..  ..\n",
       "995   1   1   0   0   1   1   1   0   1   1   1   0\n",
       "996   0   1   0   0   0   1   1   0   0   0   0   1\n",
       "997   0   1   1   1   0   0   0   0   0   1   0   0\n",
       "998   0   1   0   1   0   0   1   0   0   0   0   0\n",
       "999   1   0   0   0   0   0   1   0   0   1   0   0\n",
       "\n",
       "[1000 rows x 12 columns]"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = pd.DataFrame([[int(j) for j in i] for i in input.split(\"\\n\")])\n",
    "data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Part 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [],
   "source": [
    "def binarize_row(df):\n",
    "    bits = len(df.columns)\n",
    "    return (df.T.iloc[:,0] * (2 ** pd.Series(range(bits-1, -1, -1)))).sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "      <th>5</th>\n",
       "      <th>6</th>\n",
       "      <th>7</th>\n",
       "      <th>8</th>\n",
       "      <th>9</th>\n",
       "      <th>10</th>\n",
       "      <th>11</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   0   1   2   3   4   5   6   7   8   9   10  11\n",
       "0   1   0   1   1   1   1   1   1   1   1   0   1"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "modes = data.mode(axis=0)\n",
    "modes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(3069, 1026)"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gamma   = binarize_row(modes)\n",
    "\n",
    "## Epsilon and Gamma must add to binary 11111\n",
    "bits = len(data.columns)\n",
    "epsilon = (2 ** bits) - gamma - 1\n",
    "gamma, epsilon"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3148794"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gamma * epsilon"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Part 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [],
   "source": [
    "bits = len(data.columns)\n",
    "\n",
    "filter_max = pd.Series(data=True, index=data.index)\n",
    "filter_min = pd.Series(data=True, index=data.index)\n",
    "\n",
    "for i in range(bits):\n",
    "    filter_max = (data[i] == data.loc[filter_max, i].value_counts().index[0] ) & filter_max\n",
    "    filter_min = (data[i] == data.loc[filter_min, i].value_counts().index[-1]) & filter_min\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "      <th>5</th>\n",
       "      <th>6</th>\n",
       "      <th>7</th>\n",
       "      <th>8</th>\n",
       "      <th>9</th>\n",
       "      <th>10</th>\n",
       "      <th>11</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>112</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     0   1   2   3   4   5   6   7   8   9   10  11\n",
       "112   1   0   0   1   0   0   1   0   1   1   0   1"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data[filter_max]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "      <th>5</th>\n",
       "      <th>6</th>\n",
       "      <th>7</th>\n",
       "      <th>8</th>\n",
       "      <th>9</th>\n",
       "      <th>10</th>\n",
       "      <th>11</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>992</th>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     0   1   2   3   4   5   6   7   8   9   10  11\n",
       "992   0   1   0   0   1   0   1   0   0   1   1   0"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data[filter_min]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(2349, 1190)"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "oxygen = binarize_row(data[filter_max])\n",
    "co2    = binarize_row(data[filter_min])\n",
    "(oxygen, co2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2795310"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(oxygen * co2)"
   ]
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "758146b731c3fd8b39ea7cab27c121b86244c5bbc1f629f2f080e03f5074f425"
  },
  "kernelspec": {
   "display_name": "Python 3.9.7 64-bit ('fdap': conda)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
